package com.example.baselibrary.Utils;

public class InstructUtils {

    private static InstructUtils instance;

    public static synchronized InstructUtils getInstance() {
        if (null == instance) {
            instance = new InstructUtils();
        }
        return instance;
    }


    //组装  字符串
    public String personNumber(int s) {
        StringBuffer stringBuffer = new StringBuffer();
        if (s < 100) {
            stringBuffer.append("2A");
            stringBuffer.append("09");
            stringBuffer.append("01");
            stringBuffer.append("00");
            if (s < 10) {
                stringBuffer.append(0);
                stringBuffer.append(s + "");
            } else {
                stringBuffer.append(s + "");
            }
            stringBuffer.append("00");
            stringBuffer.append("00");
            stringBuffer.append("02");
            stringBuffer.append("2F");

        } else if (100 <= s && s <= 9999) {
            stringBuffer.append("2A");
            stringBuffer.append("09");
            stringBuffer.append("01");
            if (s <= 999) {
                stringBuffer.append(0);
                stringBuffer.append(s + "");
            } else {
                stringBuffer.append(s + "");
            }
            stringBuffer.append("00");
            stringBuffer.append("00");
            stringBuffer.append("02");
            stringBuffer.append("2F");
        }

        return String.valueOf(stringBuffer);
    }

    //获取三杆闸机返回的结果  2A1106000100000000002F
    public int showPersonNumber(String s) {
        if (s.length() == 22) {
            String number = s.substring(6, s.length());
            number = number.substring(0, 4);
            int result = Integer.parseInt(number);
            return result;
        }else {
            return 0;
        }
    }
}
